package com.gzhryc.shared_device.oem.h5.mng.controllers.market.cloud;

import com.gzhryc.common.StringTools;
import com.gzhryc.common.data.dto.ListResult;
import com.gzhryc.net_marketing.cloud.business.dao.db.CloudGoodsPayOrder;
import com.gzhryc.net_marketing.cloud.business.services.CloudGoodsPayOrderService;
import com.gzhryc.net_marketing.cloud.business.services.dto.CloudGoodsPayOrderSearch;
import com.gzhryc.net_marketing.core.enums.GoodsOrderEnum;
import com.gzhryc.servlet.DtoConstants;
import com.gzhryc.servlet.WebUtils;
import com.gzhryc.servlet.annotation.Route;
import com.gzhryc.shared_device.oem.h5.mng.WebConstants;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class CloudGoodsPayOrderController {

    @Route(value = { "/business/goods_pay_order/list.html" })
    public String list(HttpServletRequest request) {
        request.setAttribute("stateList", GoodsOrderEnum.State.values());
        return "/business/goods_pay_order/list.html";
    }

    @Route(value = "/business/goods_pay_order/list.data")
    public ListResult<CloudGoodsPayOrder> listData(HttpServletRequest request) {
        ListResult<CloudGoodsPayOrder> result = new ListResult<>(DtoConstants.NULL_DATA, "暂无数据");
        CloudGoodsPayOrderSearch search = WebUtils.getParameter(request, CloudGoodsPayOrderSearch.class);
        Integer pageNo = WebUtils.getInteger(request, "page", 1);
        Integer pageLimit = WebUtils.getInteger(request, "limit", WebConstants.PAGE_LIMIT);

        result.getBody().setTotal(CloudGoodsPayOrderService.self().countBySearch(search));
        List<CloudGoodsPayOrder> data = CloudGoodsPayOrderService.self().findBySearch(search, pageNo, pageLimit);
        if(data != null && data.size() > 0){
            result.getBody().setData(data);
            result.setCode(DtoConstants.SUCCESS, null);
        }
        return result;
    }

    @Route(value = { "/business/goods_pay_order/info.html" })
    public String info(HttpServletRequest request) {
        String tradeNo = WebUtils.getString(request,"tradeNo");
        if(StringTools.isNotBlank(tradeNo)){
            CloudGoodsPayOrder goodsPayOrder = CloudGoodsPayOrderService.self().getByTradeNo(tradeNo);
            WebUtils.setAttribute(request,goodsPayOrder);
        }
        return "/business/goods_pay_order/info.html";
    }
}
